package com.android.canvasproject.model.entity;

import java.text.ParseException;
import java.util.Map;

import android.util.Log;

import com.android.canvasproject.view.utils.ConstantsAction;

public class Postit extends GenericEntity {

	private static final long serialVersionUID = -6114420670991066876L;

	private Integer id;

	private String title;

	private String description;

	private float positionX;

	private float positionY;

	private ColorEnum color;

	private Integer sponsor;

	private Integer canvas;
	
	public static Postit entityStructure(Map<String, Object> map) {
		Postit postit = new Postit();

		try{
			postit.setId((Integer) map.get("_id"));
			postit.setTitle((String) map.get("title"));
			postit.setColor(ColorEnum.values()[(Integer) map.get("color")]);
			postit.setDescription((String) map.get("description"));
			postit.setPositionX(Float.valueOf(String.valueOf(map.get("position_x"))));
			postit.setPositionY(Float.valueOf(String.valueOf(map.get("position_y"))));

			postit.setSponsor((Integer) map.get("id_person_sponsor"));
			postit.setCanvas((Integer) map.get("id_canvas"));

			postit.entityStruture(map);

		} catch (ParseException e) {
			Log.e(Canvas.class.getName(), ConstantsAction.Error.PARSE_ERROR, e);
			throw new org.apache.http.ParseException();

		} 

		return postit;
	}

	public static class PostitDao {
		public static final String TB_POSTIT = "POSTIT";

		public static final String[] COLS_POSTIT = new String[] { "_id",
				"title", "description", "position_x", "position_y", "color",
				"id_person_sponsor", "id_canvas", "id_ics", "creation_date",
				"last_sync", "last_notification", "local_creation",
				"is_synchronized" };
		
		public static final String DB_CREATE_POSTIT = "CREATE TABLE IF NOT EXISTS POSTIT (_id INTEGER PRIMARY KEY, title VARCHAR(60) NOT NULL, description TEXT NULL, position_x FLOAT NOT NULL,  position_y FLOAT NOT NULL,  color INT DEFAULT 2, id_person_sponsor INTEGER NOT NULL, id_canvas INTEGER NOT NULL, id_ics BIGINT UNIQUE, creation_date DATETIME DEFAULT CURRENT_TIMESTAMP, last_sync TIMESTAMP NULL, last_notification TIMESTAMP NULL, local_creation INT DEFAULT 0, is_synchronized INT DEFAULT 0, CONSTRAINT fk_postit_person FOREIGN KEY (id_person_sponsor) REFERENCES PERSON (_id), CONSTRAINT fk_postit_canvas FOREIGN KEY (id_canvas) REFERENCES CANVAS (_id));";
	}

	public Postit() {
		super();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public float getPositionX() {
		return positionX;
	}

	public void setPositionX(float positionX) {
		this.positionX = positionX;
	}

	public float getPositionY() {
		return positionY;
	}

	public void setPositionY(float positionY) {
		this.positionY = positionY;
	}

	public ColorEnum getColor() {
		return color;
	}

	public void setColor(ColorEnum color) {
		this.color = color;
	}

	public Integer getSponsor() {
		return sponsor;
	}

	public void setSponsor(Integer sponsor) {
		this.sponsor = sponsor;
	}

	public Integer getCanvas() {
		return canvas;
	}

	public void setCanvas(Integer canvas) {
		this.canvas = canvas;
	}
}